import {AppState} from "../types";

const useAppStore = defineStore("useAppStore", {
    state: (): AppState => ({
        isCollapse: 1,
        userFlag: true,
        backgroundImg: 1,
        backgroundImgList: [0, 1, 2, 3, 4, 5, 6],
        iconColor: "#CC57F3",
        searchFlag: false,
        loginFlag: false,
        registerFlag: false,
        forgetFlag: false,
        emailFlag: false,
        sideFlag: false,
        chatFlag: false,
        isBrand: true,
        isHandler: 0,
        volume: 0,
        isDark: false,
        themeName: "default",
        isThemeBg: false,
        isController: false,
        specialFlag: 1,
    }),
    actions: {
        setCollapse(num: number) {
            this.isCollapse = num;
        },
        setUserFlag(flag: boolean) {
            this.userFlag = flag;
        },
        setBackgroundImg(num: number) {
            this.backgroundImg = num;
        },
        setIconColor(color: string) {
            this.iconColor = color;
        },
        setLoginFlag(flag: boolean) {
            this.loginFlag = flag;
        },
        setRegisterFlag(flag: boolean) {
            this.registerFlag = flag;
        },
        setForgetFlag(flag: boolean) {
            this.forgetFlag = flag;
        },
        setIsDark() {
            if (this.isDark) {
                this.isDark = false;
                document.documentElement.setAttribute('theme-sys', "light");
            } else {
                this.isDark = true;
                document.documentElement.setAttribute('theme-sys', "dark");
            }
        }
    },
    getters: {},
    persist: {
        key: "app",
        storage: sessionStorage,
    },
});

export default useAppStore;
